<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<%@ include file="../common/common.jsp"%>
		<script type="text/javascript" src="${ctx}/lib/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" src="${ctx}/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
		<title>外部订单</title>
	</head>

	<body>
		<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页<span class="c-gray en">&gt;</span> 订单管理 <span class="c-gray en">&gt;</span> 外部订单                       
			<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
		</nav>
		<div class="page-container">
			<div class="text-c">
				外部订单号：
				<input type="text" id="orderNo" placeholder=" 订单号" style="width:200px" class="input-text mr-10"> 
				用户ID：
				<input type="text" id="cardNo" placeholder=" 用户ID" style="width:200px" class="input-text mr-10"> 
				上级用户ID：
				<input type="text" id="chiefCardNo" placeholder=" 上级用户ID" style="width:200px" class="input-text mr-10"> 
				<p></p>
				兑换时间：
				<input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}'})" id="logmin" class="input-text Wdate" style="width:160px;">
					-
				<input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d'})" id="logmax" class="input-text Wdate" style="width:160px;">
				<button id="search" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
			</div>
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">

				</span>
			</div>
			<div class="mt-20">
				<table id="table" class="table table-border table-bordered table-bg table-hover table-sort">
					<thead>
						<tr class="text-c">
							<th width="25"><input type="checkbox" name="checkAll" value=""></th>
							<th>序号</th>
							<th>外部订单号</th>
							<th>用户ID</th>
							<th>上级ID</th>
							<th>支付金额</th>
							<th>赠送积分</th>
							<th>赠送贝币</th>
							<th>上级会员贝币分成</th>
							<th>上级代理贝币分成</th>
							<th>上级会员积分分成</th>
							<th>上级代理积分分成</th>
							<th>兑换时间</th>
							<th>结算标志</th>
							<th>结算时间</th>
							<th>备注</th>
							<th>操作</th>
						</tr>
					</thead>
				<tbody>
					<tr class="text-c">
						<td colspan="9">数据获取中....</td>
					</tr>
				</tbody>
			</table>
			</div>
		</div>
	<script type="text/javascript">
			$('#table').dataTable({
				"dom": '<"datatable-header"<"dataTables_filter">l><"datatable-scroll"t><"datatable-footer"ip>',
				"aaSorting": [[ 14, "desc" ]],//默认第几个排序
				"bStateSave": false,//状态保存
				"aoColumnDefs": [
				     			////{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
				     			{"orderable":false,"aTargets":[0,1,2,3,4,15,16]} // 不参与排序的列
				     		],
				"columnDefs":[
				    		  	{
				    		  		//设置列不参与搜索
				    		  		"targets":[0,1,5,6,7,8,9,10,11,12,13,15,16],
				    		  		"serchable":false
				    		  	}
				    		  ],
				"bProcessing": true, //开启读取服务器数据时显示正在加载中……特别是大数据量的时候，开启此功能比较好
				"bServerSide": true,
				"sAjaxSource": ctx + "/orderManage/findOutOrderExchangePage.do",//ajax地址 
	          	//配置列要显示的数据
	            "aoColumns": [
					{"sDefaultContent": ''},
					{"sDefaultContent": ''},
					{ "mData": "outOrderNo" },
					{ "mData": "cardNo" },
					{ "mData": "chiefCardNo" },
					{ "mData": "payAmount" },
					{ "mData": "givePoint" },
					{ "mData": "giveJinBi" },
					{ "mData": "chiefBaseVipJinBi" },
					{ "mData": "chiefHighVipJinBi" },
					{ "mData": "chiefBaseVipPoint" },
					{ "mData": "chiefHighVipPoint" },
	    			{ "mData": 'exchangeTime', "mRender": function ( data, type, full ) {
	    				if(empty(full.exchangeTime)){
	    					return "-";
	    				}else{
	    					return dates(full.exchangeTime);
	    				}
	    			}},
	    			{ "mData": "settleFlag" },
	    			{ "mData": 'settleTime', "mRender": function ( data, type, full ) {
	    				if(empty(full.settleTime)){
	    					return "-";
	    				}else{
	    					return dates(full.settleTime);
	    				}
	    			}},
	    			{ "mData": 'remark', "mRender": function ( data, type, full ) {
	    				if(empty(full.remark)){
	    					return "-";
	    				}else{
	    					return full.remark;
	    				}
	    			}},
	            	{"sDefaultContent": ''} // sDefaultContent 如果这一列不需要填充数据用这个属性，值可以不写，起占位作用
	            ],
				"fnServerData": retrieveData,//执行方法
				"fnRowCallback": fnRowCallback
			});
			//给搜索按钮绑定点击事件
			$(document).on("click","#search",
					function() {
						//自己定义的搜索框，可以是时间控件，或者checkbox 等等
						var data = {};
						var outOrderNo = $("#outOrderNo").val();
						if(outOrderNo.length != 0){
							data.outOrderNo = outOrderNo;
						}
						var cardNo = $("#cardNo").val();
						if(cardNo.length != 0){
							data.cardNo = cardNo;
						}
						var chiefCardNo = $("#chiefCardNo").val();
						if(chiefCardNo.length != 0){
							data.chiefCardNo = chiefCardNo;
						}
						var startTime = $("#logmin").val();
						var endTime = $("#logmax").val();
						if(startTime.length == 0 && endTime.length == 0){
							
						}else{
							var _startTime = getUnixTime(startTime)+"";
							var _endTime = getUnixTime(endTime)+"";
							if(_startTime.length == 0){
								_startTime = "0";
							}
							if(_endTime.length == 0){
								_endTime = "0";
							}
							data.exchangeTime = _startTime + "," + _endTime;
						}
						$('#table').DataTable().search(JSON.stringify(data)).draw();
					});
		function retrieveData(sSource, aoData, fnCallback) {
			var index = layer.load(0, {shade: false});
		    $.ajax({
		        type: "POST",
		        contentType: "application/x-www-form-urlencoded",
		        url: sSource,
		        dataType: "json",
		        data: aoData, 
		        success: function (resp) {
		        	layer.close(index);
		        	if(resp.code != "ok"){
						console.log("返回失败", resp);
						layer.msg(resp.msg,{icon: 5,time:2000});
		        	}else{
		        		var bizData = resp.object;
				        var data={
								"sEcho":bizData.userdata.sEcho, //当前显示的第一条数据
								"iTotalRecords":bizData.records,  //总记录数
								"iTotalDisplayRecords":bizData.records,  //当前显示的总记录数
								"aaData":bizData.rows //数据列表
				        };
				        fnCallback(data); //服务器端返回的对象的returnObject部分是要求的格式  	
		        	}
		        },
				error: function(data) {
					console.log("返回失败", data);
					layer.close(index);
					layer.msg(data.msg,{icon: 5,time:2000});
					$("table tbody").html('<tr class="text-c"><td colspan="11">'+data.msg+'...</td></tr>');
				}
		    });
		}
		
		// 当创建了行，但还未绘制到屏幕上的时候调用，通常用于改变行的
		function fnRowCallback(nRow, aData, iDisplayIndex) {
			$(nRow).addClass('text-c');
			$('td:eq(0)', nRow).html("<input type='checkbox' value='"+aData.id+"' name='del'>");
			$('td:eq(1)', nRow).html(iDisplayIndex+1);
			
			if(aData.settleFlag == 0){
				$('td:eq(13)', nRow).html("<span class='label label-default radius'>未结算</span>");
			}else if(aData.settleFlag == 1){
				$('td:eq(13)', nRow).html("<span class='label label-success radius'>已结算</span>");
			}
			
			return nRow;
		}
	</script>
	<script type="text/javascript">
	/*备注*/
	function addRemark(title,orderNo){
		var url = ctx + "/orderManage/addMobileOrderRemark.html?orderNo=" + orderNo;;
		layer_show(title,url,"",200);
	}
	
	/*完成*/
	function complete(title, orderNo){
		var tip = "确定要完成吗？";
		layer.confirm(tip,function(index){
			var index = layer.load(0, {shade: false});
			$.ajax({
				type : 'POST',
				url : ctx + '/orderManage/completeMobileOrder.do',
				data : {
					orderNo : orderNo
				},
				dataType : 'json',
				timeout : 30000,
				context : $('body'),
				success : function(data) {
					layer.close(index);
					if (data.code == "ok") {
						window.location.reload();
					} else {
						 layer.msg(data.msg, {icon: 5, time: 2000});
					}
				},
				error : function(xhr, type) {
					layer.close(index);
					layer.msg('操作失败!', {icon: 5, time: 2000});
				}
			});
		});
	}
	
	</script>

</body>

</html>